
var Filter = new Class.create();
Filter.prototype = {
    filter:{
        grayscale:"",
        saturate:"",
        sepia:"",
        invert:"",
        opacity:"",
        brightness:"",
        contrast:"",
        hue_rotate:"",
        blur:"",
        style:"",
    },
    Conf:{
        grayscale:{min:0,max:100,default:0,unit:"%",name:"灰度"},
        saturate:{min:0,max:500,default:100,unit:"%",name:"饱和度"},
        sepia:{min:0,max:100,default:0,unit:"%",name:"褐色"},
        invert:{min:0,max:100,default:0,unit:"%",name:"反相"},
        opacity:{min:0,max:100,default:100,unit:"%",name:"透明度"},
        brightness:{min:0,max:500,default:100,unit:"%",name:"亮度"},
        contrast:{min:0,max:500,default:100,unit:"%",name:"对比度"},
        hue_rotate:{min:0,max:360,default:0,unit:"deg",name:"色相"},
        blur:{min:0,max:50,default:0,unit:"px",name:"模糊"},
    },
    initialize:function () {

    },
    getData:function () {this.filter.style = this.getStyle() ;return this.filter;},
    setData:function(data){this.filter = data;return this;},
    getStyle:function(){
        let style = "filter:";
        for (var i in this.filter) {
            if (i == "style") {
                continue;
            }
            if (this.filter[i] == "") {
                continue;
            }
            if (i == "hue_rotate") {
                style += " hue-rotate(" + this.filter[i]  + this.Conf[i].unit + ")";
            }else {
                style += " "+ i + "(" + this.filter[i]  + this.Conf[i].unit + ")";
            }
        }
        style +=";";
        console.log(this)
        console.log(style)
        return style
    },
    setBlur:function (num) {
        if (num === this.filter.blur) { this.filter.blur = "";return this; }
        if (num > this.Conf.blur.max) { num =  this.Conf.blur.max }
        if (num < this.Conf.blur.min) { num =  this.Conf.blur.min }
        if (num !== this.Conf.blur.default) { this.filter.blur = num }
        return this;
    },
    setContrast:function (num) {
        if (num === this.filter.contrast) { this.filter.contrast = "";return this; }
        if (num > this.Conf.contrast.max) { num =  this.Conf.contrast.max }
        if (num < this.Conf.contrast.min) { num =  this.Conf.contrast.min }
        if (num !== this.Conf.contrast.default) { this.filter.contrast = num }
        return this;
    },
    setHueRotate:function (num) {
        if (num === this.filter.hue_rotate) { this.filter.hue_rotate = "";return this; }
        if (num > this.Conf.hue_rotate.max) { num =  this.Conf.hue_rotate.max }
        if (num < this.Conf.hue_rotate.min) { num =  this.Conf.hue_rotate.min }
        if (num !== this.Conf.hue_rotate.default) { this.filter.hue_rotate = num }
        return this;
    },
    setBrightness:function (num) {
        if (num === this.filter.brightness) { this.filter.brightness = "";return this; }
        if (num > this.Conf.brightness.max) { num =  this.Conf.brightness.max }
        if (num < this.Conf.brightness.min) { num =  this.Conf.brightness.min }
        if (num !== this.Conf.brightness.default) { this.filter.brightness = num }
        return this;
    },
    setOpacity:function (num) {
        if (num === this.filter.opacity) { this.filter.opacity = "";return this; }
        if (num > this.Conf.opacity.max) { num =  this.Conf.opacity.max }
        if (num < this.Conf.opacity.min) { num =  this.Conf.opacity.min }
        if (num !== this.Conf.opacity.default) { this.filter.opacity = num }
        return this;
    },
    setGrayScale:function (num) {
        if (num === this.filter.grayscale) { this.filter.grayscale = "";return this; }
        if (num > this.Conf.grayscale.max) { num =  this.Conf.grayscale.max }
        if (num < this.Conf.grayscale.min) { num =  this.Conf.grayscale.min }
        if (num !== this.Conf.grayscale.default) { this.filter.grayscale = num }
        return this;
    },
    setSaturate:function (num) {
        if (num === this.filter.saturate) { this.filter.saturate = "";return this; }
        if (num > this.Conf.saturate.max) { num =  this.Conf.saturate.max }
        if (num < this.Conf.saturate.min) { num =  this.Conf.saturate.min }
        if (num !== this.Conf.saturate.default) { this.filter.saturate = num }
        return this;
    },
    setSepia:function (num) {
        if (num === this.filter.sepia) { this.filter.sepia = "";return this; }
        if (num > this.Conf.sepia.max) { num =  this.Conf.sepia.max }
        if (num < this.Conf.sepia.min) { num =  this.Conf.sepia.min }
        if (num !== this.Conf.sepia.default) { this.filter.sepia = num }
        return this;
    },
    setInvert:function (num) {
        if (num === this.filter.invert) { this.filter.invert = "";return this; }
        if (num > this.Conf.invert.max) { num =  this.Conf.invert.max }
        if (num < this.Conf.invert.min) { num =  this.Conf.invert.min }
        if (num !== this.Conf.invert.default) { this.filter.invert = num }
        return this;
    },
    reset:function () {
        this.filter = {
            grayscale:"",
            saturate:"",
            sepia:"",
            invert:"",
            opacity:"",
            brightness:"",
            contrast:"",
            hue_rotate:"",
            blur:"",
            style:"",
        }
        return this;
    }
}